// hyb_yl/krecovery/pages/postoperative_ordercont/postoperative_ordercont.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    back_orser:"",
    doc:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
 
  onLoad: function (options) {
    var that = this;
    that.setData({
      back_orser:options.back_orser,
      id:options.id
    })
    var key_words = options.key_words;
    that.getOrder();
    if(options.doc != '' && options.doc != undefined)
    {
      that.setData({
        doc:options.doc
      })
    }
    var bgc=wx.getStorageSync('color');
    this.setData({
      bgc:bgc
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
  },
  // 专家接诊
  jiezhen:function(){
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.updateghorder',
      data: {
        back_orser: that.data.info.back_orser
      },
      success(res) {
        app.util.request({
          'url':"entry/wxapp/zhuanjia.ghjzmsgdh",
          data:{
            id:that.data.info.id
          },
          success:function(res){

          }
        })
        console.log(res)
        that.getOrder();
      }
    })
  },
  // 获取订单详情
  getOrder:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/zhuanjia.gh_detail",
      data:{
        back_orser:that.data.back_orser,
        id:that.data.id,
      },
      success:function(res)
      {
        that.setData({
          info:res.data
        })
      }
    })
  },
  // 专家添加随访
  suifan:function(e){
    var that = this;
    var j_id = that.data.info.j_id;
    var names = that.data.info.names;
    var telphone = that.data.info.telphone;
    var back_orser = that.data.info.back_orser;
    var numcard = that.data.info.numcard;
    var sex = that.data.info.sex;
    var openid = that.data.info.openid;
    var age = that.data.zid.age;
    var zid = that.data.info.zid;
    wx.navigateTo({
      url: '/hyb_yl/krecovery/pages/followUp/followUp?j_id='+j_id+'&names='+names+'&telphone='+telphone+'&back_orser='+back_orser+'&numcard='+numcard+'&sex='+sex+'&openid='+openid+'&age='+age+'&zid='+zid,
    })
  },
  getchar(e) {
    var that = this
    var id = that.data.info.id
    var zid = that.data.info.zid
    var typedate = e.currentTarget.dataset.typedate
    var key_words = that.data.key_words
    var j_id = that.data.info.j_id
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/yishengkaifang/yishengkaifang?id=' + id + '&zid=' + zid + '&typedate=' + typedate + '&key_words=' + key_words + '&zid=' + zid + '&j_id=' + j_id,
    })
  },
  bindphone:function(e){
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.tel,
    })
  },
  // 取消订单
  quxiao:function(){
    var that = this;
    var key_words = that.data.key_words;
    
      app.util.request({
        'url':"entry/wxapp/zhuanjia.gh_quxiao",
        data:{
          id:that.data.info.id,
          ifpay:6
        },
        success:function(res){
          that.getOrder();
        }
      })
    
    
  },
  // 支付订单
  topay:function(e){
    var that = this
    var orders = that.data.info.order;
    var money = that.data.info.money;
    var key_words = that.data.info.key_words;
    var id = that.data.info.id;
    var zid = that.data.info.zid;
    
    app.util.request({
      'url': 'entry/wxapp/yuyue.paywenzhen',
      header: {
        "Content-Type": "application/xml"
      },
      method: "GET",
      data: {
        openid: wx.getStorageSync('openid'),
        z_tw_money: money,
        orders: orders,
        key_words: key_words
      },
      success: function (res) {
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr, //字符串随机数
          'package': res.data.package,
          'signType': res.data.signType,
          'paySign': res.data.paySign,
          success: function (res) {
            console.log(res)

          },
          fail: function (res) {
            console.log(res)

          },
          'complete': function (res) {
            //更新问诊时间
            if (res.errMsg == 'requestPayment:ok') {
              
                app.util.request({
                  'url': 'entry/wxapp/zhuanjia.updateghorder',
                  data: {
                    back_orser: orders,
                  },
                  success: function (res) {
                    console.log(res)
                    that.getOrder();
                  }
                })
              
              
              
              //模板消息提醒
              app.util.request({
                'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                data: {
                  id: id,
                  near: '远程挂号',
                  zid: zid
                },
                success: function (res) {
                  console.log(res)
                  that.setData({
                    page:0,
                    list:[],
                  })
                  
                }
              })
            }
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})